#include <stdio.h>
#include <stdlib.h>

int main (int argc, char const* argv[])
{
    int m, t, u, f, d, flg, i;
    char path, buf[2];

    scanf("%d %d %d %d %d", &m, &t, &u, &f, &d);

    flg = 1;
    for (i = 0; i < t; i++) {
        scanf("%s", buf);
        path = buf[0];

        if (flg) {
            if (m < 0) {
                printf("%d\n", i-1);
                flg = 0;
            }
            if ('u' == path || 'd' == path) {
                m -= u + d;
            } else if ('f' == path) {
                m -= 2 * f;
            }
        }
    }

    return 0;
}
